using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;

namespace MVExplorer.Components
{
	public partial class AddNewKeyword : System.Windows.Controls.UserControl
	{
		public event EventHandler Canceled;
		public event EventHandler Ok;
		private int idTargetSegment = -1;

		public AddNewKeyword()
		{
			InitializeComponent();

			cmdOk.Click += new RoutedEventHandler(cmdOk_Click);
			cmdCancel.Click += new RoutedEventHandler(cmdCancel_Click);
			this.Loaded += new RoutedEventHandler(AddNewKeyword_Loaded);
			this.LostFocus += new RoutedEventHandler(AddNewKeyword_LostFocus);
			textKeyword.GotFocus += new RoutedEventHandler(textKeyword_GotFocus);
		}

		void textKeyword_GotFocus(object sender, RoutedEventArgs e)
		{
			InputMethod.SetIsInputMethodEnabled(textKeyword, true);
			InputMethod im = InputMethod.Current;
			im.HandwritingState = InputMethodState.On;
		}

		void AddNewKeyword_Loaded(object sender, RoutedEventArgs e)
		{
			textKeyword.SelectAll();
			textKeyword.Focus();

		}

		void AddNewKeyword_LostFocus(object sender, RoutedEventArgs e)
		{

		}

		void cmdOk_Click(object sender, RoutedEventArgs e)
		{
			e.Handled = true;
			if (this.Ok != null)
				this.Ok(this, new EventArgs());
		}

		void cmdCancel_Click(object sender, RoutedEventArgs e)
		{
			e.Handled = true;
			if (this.Canceled != null)
				this.Canceled(this, new EventArgs());
		}

		public int TargetSegment
		{
			get { return idTargetSegment; }
			set { idTargetSegment = value; }
		}

		public string NewKeyword
		{
			get { return textKeyword.Text; }
			set { textKeyword.Text = string.Copy(value); }
		}
	}
}